require 'Korundum'
include KDE

require 'view_globals'


class WorkspaceSelectionDialog < KDE::DialogBase
	def initialize
		caption = 'Select a workspace'
		super(ViewGlobals.instance.main_view,'open_workspace', true, caption, KDE::DialogBase::Ok | KDE::DialogBase::Cancel, KDE::DialogBase::Ok)
		page = makeVBoxMainWidget();
		
		label = Qt::Label.new( caption, page, "caption" );
		@list_view = KDE::ListView.new(page, 'list')
		@list_view.all_columns_show_focus = true
		@list_view.add_column('Name')
		@list_view.add_column('Description')
		
		@items = {}
	end

	def show_modal
		self.exec
	end

	def add_workspace(id, name, description)
		item = Qt::ListViewItem.new(@list_view, String.new(name), String.new(description))
		@items[item] = id
	end
	
	def selected
		return nil if result != Qt::Dialog::Accepted || !@list_view.selected_item
		@items[@list_view.selected_item]
	end
end
